package org.yun.demo.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.yun.demo.service.dto.StudentDTO;

import java.util.concurrent.CompletableFuture;

/**
 * Created with IDEA
 * author:yunxf
 * Date:2019/9/9
 * Time:10:52 AM
 */
@Service
@Async
public class StudentAsyncServiceImpl implements StudentAsyncService {


    @Override
    public CompletableFuture<String> getName() {
        CompletableFuture<String> future = new CompletableFuture<>();
        try {
            System.out.println(Thread.currentThread().getName());
            Thread.sleep(500L);
            future.complete("yunxf async");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return future;
    }

    @Override
    public String getStudentName() {
        System.out.println(Thread.currentThread().getName());
        return "yunxf sync";
    }

    @Override
    public CompletableFuture<StudentDTO> getStudentDto() {
        CompletableFuture<StudentDTO> future = new CompletableFuture<>();
        StudentDTO studentDTO = StudentDTO.builder().age("11").name("test yun").build();
        future.complete(studentDTO);
        return future;
    }
}
